package com.example.testtransition

import android.content.Context
import android.util.AttributeSet
import com.google.android.material.expandable.ExpandableTransformationWidget
import com.google.android.material.expandable.ExpandableWidgetHelper
import com.google.android.material.imageview.ShapeableImageView

class CustomShapableImageView : ShapeableImageView, ExpandableTransformationWidget {

    constructor(context: Context) :
            super(context) {
        initShape(context, null, 0)
    }

    constructor(context: Context, attrs: AttributeSet?) :
            super(context, attrs) {
        initShape(context, attrs, 0)

    }

    constructor(context: Context, attrs: AttributeSet?, defStyle : Int) :
            super(context, attrs, defStyle)  {
        initShape(context, attrs, defStyle)
    }


    fun initShape(context: Context, attrs: AttributeSet?, defStyle: Int) {
        expandableWidgetHelper = ExpandableWidgetHelper(this)
        expandableWidgetHelper?.isExpanded = true
    }

    private var expandableWidgetHelper: ExpandableWidgetHelper? = null

    override fun isExpanded(): Boolean {
        return expandableWidgetHelper?.isExpanded ?: false
    }

    override fun setExpanded(expanded: Boolean): Boolean {
        return expandableWidgetHelper?.setExpanded(expanded) ?: false
    }

    override fun getExpandedComponentIdHint(): Int {
        return expandableWidgetHelper?.expandedComponentIdHint ?: 0
    }

    override fun setExpandedComponentIdHint(expandedComponentIdHint: Int) {
        expandableWidgetHelper?.expandedComponentIdHint = expandedComponentIdHint
    }


}